package com.ubeecube.mylocker.ui;

import java.util.ArrayList;

import com.ubeecube.mylocker.R;
import com.ubeecube.mylocker.viewobjects.Folder;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class LockerPhotosAdaptor extends BaseAdapter{
	
	private Context mContext;
	private ArrayList<Folder> folderList;
	private LayoutInflater lInflater;
	private ViewHolder viewHolder;
	
	public LockerPhotosAdaptor(Context context, ArrayList<Folder> folderList) {
		this.mContext = context;
		this.folderList = folderList;
	}

	@Override
	public int getCount() {
		if (folderList != null) {
			return folderList.size();
		} else {
			return 0;
		}
	}

	
	
	
	@Override
	public Object getItem(int position) {
		if (folderList != null) {
			return folderList.get(position);
		} else {
			return null;
		}
	}

	@Override
	public long getItemId(int arg0) {
		if (folderList != null) {
			return folderList.size();
		} else {
			return 0;
		}
	}

	@Override
	public View getView(int position, View convertView, ViewGroup arg2) {
		
		if(convertView == null){
			String inflater = Context.LAYOUT_INFLATER_SERVICE;
			lInflater = (LayoutInflater) mContext.getSystemService(inflater);
			convertView = lInflater.inflate(R.layout.photo_row_layout, null);

			viewHolder = new ViewHolder();
			viewHolder.fileName = (TextView)convertView.findViewById(R.id.title);
			
			convertView.setTag(viewHolder); 
		}else{
			viewHolder = (ViewHolder)convertView.getTag();
			convertView.setTag(viewHolder);
		}
		
		viewHolder.fileName.setText(folderList.get(position).getName());
		
		
		return convertView;
	}
	
	class ViewHolder {
		public TextView fileName;
	}

}
